#ifndef __INETADDRESS_HPP__
#define __INETADDRESS_HPP__

#include "func.hpp"

#include <string>
using std::string;

namespace wd{


class InetAddress{
public:
    //构造函数1
    InetAddress(unsigned short port, string ip){
        _addr.sin_family = AF_INET;
        _addr.sin_port = htons(port);
        _addr.sin_addr.s_addr = inet_addr(ip.c_str());
    }
    //构造函数2
    InetAddress(const struct sockaddr_in & addr)
    :_addr(addr){
    }
    //获取ip
    string ip(){
        return inet_ntoa(_addr.sin_addr);
    }
    //获取端口号
    unsigned short port(){
        return ntohs(_addr.sin_port);
    }
    //获取指针
    struct sockaddr_in* getInetAddrptr(){
        return &_addr;
    }

private:
    struct sockaddr_in _addr;
};


}


#endif // __INETADDRESS_HPP__

